package com.jpa.demo.factorybeanexample;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

/**
 * 这是一个FactoryBean
 */
@Component
public class UserServiceFactoryBean implements FactoryBean<UserService> {

    @Override
    public UserService getObject() {
//        Proxy.newProxyInstance(getClass().getClassLoader(),
//                new Class[]{UserService.class},
//                (proxy,method,args) -> {
//                    System.out.println("Before method: " + method.getName());
//                    return method.invoke(new UserService("Proxy"), args);
//        });
        return new UserService("Created by FactoryBean");
    }

    @Override
    public Class<?> getObjectType() {
        return UserService.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
